package nbcp.base.model

import com.jcraft.jsch.SftpProgressMonitor
import nbcp.base.extend.AsInt

class DefaultSftpProgressMonitor(var progressCallback: ((Int) -> Unit)?) : SftpProgressMonitor {
    var progress:Int = 0;
    var total = 0L;
    var uploadLen = 0L;
    var invokedProgress = 0;

    override fun init(op: Int, src: String , dest: String , max: Long) {
        total = max;
    }

    override fun count(count: Long): Boolean {
        uploadLen += count;
        if( total == 0L ) {
            return true;
        }

        progress = (uploadLen * 100 / total).AsInt()

        if( (progress / 10).AsInt()  != invokedProgress  ) {
            invokedProgress = (progress / 10).AsInt()

            progressCallback?.invoke(progress)
        }

        return true;
    }

    override fun end() {

    }

}
